package operation;

import result.Score;
import result.ScoreList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(ScoreList scoreList) {
        System.out.println("删除成绩！！");
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要删除成绩的学生名字:");
        String name=sc.nextLine();
        System.out.println("请输入要删除成绩的学生学号:");
        String studentID=sc.nextLine();
        System.out.println("请输入要删除成绩的课程名称:");
        String courseName=sc.nextLine();
        int size=scoreList.getSize();
        int i=0;
        int pos=0;
        for(;i<size;i++){
            Score score=scoreList.getScores(i);
            if(score.getName().equals(name)&&score.getStudentID().equals(studentID)&&score.getCourseName().equals(courseName)){
                pos=i;
                System.out.println("删除成功！");
                break;
            }
        }
        if(i==size){
            System.out.println("没有该学生成绩，请重新输入！");
        }
        for(;pos<size-1;pos++){
            Score score=scoreList.getScores(pos+1);
            scoreList.setScores(pos,score);
        }
        scoreList.setSize(size-1);
    }
}
